package com.rahms.server.controller;

import com.rahms.common.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * API文档示例控制器
 */
@RestController
@RequestMapping("/api-docs")
@Tag(name = "API文档", description = "API文档相关接口")
public class ApiDocumentationController {

    @GetMapping("/info")
    @Operation(summary = "获取API信息", description = "获取API文档的基本信息")
    public R<Map<String, Object>> getApiInfo() {
        Map<String, Object> info = new HashMap<>();
        info.put("title", "社区老年人用药提醒与健康管理系统 API");
        info.put("version", "1.0.0");
        info.put("description", "基于Spring Boot的社区老年人用药提醒与健康管理系统");
        info.put("contact", Map.of(
                "name", "RAHMS开发团队",
                "email", "rahms@example.com",
                "url", "https://github.com/rahms/community-elderly-medication-management"
        ));
        info.put("license", Map.of(
                "name", "MIT License",
                "url", "https://opensource.org/licenses/MIT"
        ));
        info.put("servers", new String[]{
                "http://localhost:8080 (开发环境)",
                "https://api.rahms.com (生产环境)"
        });
        return R.success(info);
    }

    @GetMapping("/endpoints")
    @Operation(summary = "获取API端点列表", description = "获取所有可用的API端点")
    public R<Map<String, String[]>> getApiEndpoints() {
        Map<String, String[]> endpoints = new HashMap<>();
        endpoints.put("认证管理", new String[]{
                "POST /auth/register - 用户注册",
                "POST /auth/login - 用户登录"
        });
        endpoints.put("用户管理", new String[]{
                "GET /user/me - 获取当前用户信息",
                "PUT /user/me - 更新用户信息",
                "POST /user/change-password - 修改密码",
                "GET /user/list - 获取用户列表"
        });
        endpoints.put("老人信息管理", new String[]{
                "GET /elderly - 获取老人列表",
                "GET /elderly/detail - 获取老人详情",
                "POST /elderly/add - 添加老人信息",
                "POST /elderly/update - 更新老人信息",
                "POST /elderly/delete - 删除老人信息"
        });
        endpoints.put("药品管理", new String[]{
                "GET /medications - 获取药品列表",
                "GET /medications/detail - 获取药品详情",
                "POST /medications/add - 添加药品",
                "POST /medications/update - 更新药品",
                "POST /medications/delete - 删除药品"
        });
        endpoints.put("用药计划管理", new String[]{
                "GET /drug-plans - 获取用药计划列表",
                "GET /drug-plans/detail - 获取用药计划详情",
                "POST /drug-plans/add - 添加用药计划",
                "POST /drug-plans/update - 更新用药计划",
                "POST /drug-plans/delete - 删除用药计划"
        });
        endpoints.put("健康数据管理", new String[]{
                "GET /health-data/by-type - 根据类型获取健康数据",
                "GET /health-data/by-date - 根据日期范围获取健康数据",
                "GET /health-data/statistics - 获取健康数据统计",
                "POST /health-data/add - 添加健康数据",
                "POST /health-data/update - 更新健康数据"
        });
        endpoints.put("缓存管理", new String[]{
                "POST /cache/clear-all - 清除所有缓存",
                "POST /cache/clear-user - 清除用户缓存",
                "POST /cache/clear-medication - 清除药品缓存",
                "GET /cache/info - 获取缓存信息",
                "POST /cache/set - 设置缓存",
                "POST /cache/delete - 删除缓存"
        });
        endpoints.put("常量管理", new String[]{
                "GET /constants/messages - 获取消息常量",
                "GET /constants/cache - 获取缓存常量",
                "GET /constants/jwt-claims - 获取JWT声明常量",
                "GET /constants/auto-fill - 获取自动填充常量",
                "GET /constants/all - 获取所有常量"
        });
        return R.success(endpoints);
    }
}
